//47
//ZOGRAF G.P.
//2103
//17.11.12

#include <stdio.h>

//FILE *inf, *outf;





void printarr(int n, int m, float A[4][5]);


main()
{

//  inf=fopen("input.txt", "rt");           //open input.txt
  //outf= stdout;
  //outf=fopen("output.txt", "wt");         //open output.txt

  int i,j,k,max,n,m;
  float A[4][5],c,X[4];

  printf("47\n");                //vivod zagolovka
  printf( "ZOGRAF G.P.\n");
  printf( "2103.1\n");
  printf( "17.11.12\n");
  printf( "\n");
  n=4;
  m=5;
  
    

    A[0][0] = 5;
    A[0][1] = 1;
    A[0][2] = 1;
    A[0][3] = 1;
    A[0][4]=9;
    
    A[1][0] = 1;
    A[1][1] = 7;
    A[1][2] = 1;
    A[1][3] = 1;
    A[1][4]=11;

    A[2][0] = 1;
    A[2][1] = 1;
    A[2][2] = 9;
    A[2][3] = 1;
    A[2][4]=13;
    

    A[3][0] = 1;
    A[3][1] = 1;
    A[3][2] = 1;
    A[3][3] = 11;
    A[3][4]=15;

                               
  printarr(n,m,A);
  printf("\n");
  
  for(i=0;i<n;++i){
                   max=i;
                   for(j=i+1;j<n;++j)
                                     if (A[j][i]>A[max][i])
                                                           max=j;
                   for(j=0;j<n+1;++j){
                                      c=A[max][j];
                                      A[max][j]=A[i][j];
                                      A[i][j]=c;
                   }
                   for(j=n;j>=i;--j)
                                    for(k=i+1;k<n;++k)
                                                      A[k][j]-=A[k][i]/A[i][i]*A[i][j];
 }
                                         
                                      
  for(i=n-1;i>=0;--i){
                      A[i][n]=A[i][n]/A[i][i];
                      A[i][i]=1;
                      for(j=i-1;j>=0;--j){
                                          A[j][n]-=A[j][i]*A[i][n];
                                          A[j][i]=0;
                      }
 }
                                                         

  printarr(n,m,A);
 for (i=0;i<n;i++){
      printf("X""%2i",i+1);
      printf("= ""%2.9f",A[i][4]);
      printf("\n");
  }
  getchar();
  printf("\n""Precision check:""\n");
  printf("Row 1:""\n""theory=9""\n");
  printf("%2.9f",5*A[0][4]+A[1][4]+A[2][4]+A[3][4]);
  printf("\n""Row 2:""\n""theory=11""\n");
  printf("%2.9f",A[0][4]+7*A[1][4]+A[2][4]+A[3][4]);
  printf("\n""Row 3:""\n""theory=13""\n");
  printf("%2.9f",A[0][4]+A[1][4]+9*A[2][4]+A[3][4]);
  printf("\n""Row 4:""\n""theory=15""\n");
  printf("%2.9f",A[0][4]+A[1][4]+A[2][4]+11*A[3][4]);
  
 

  getchar();

  return 0;                               // end
}



void printarr(int n, int m, float A[4][5])
{
  int i,j;
  
  for(i=0;i<=n-1;i++,printf("\n"))
  {
                   for(j=0;j<=m-1;j++)
                   printf( "%2.9f""  ", A[i][j]);
                  // printf( "%2.9f""  ", B[i]);
  }
  //fprintf(outf,"\n");
  return;    
}
